#include <iostream>
#include <vector>

//给定一个数，如果这个数每个位上的数字的平方加起来所形成的新的数再经过若干次这种处理能够变为1，则是快乐数

/*
int happylize(int number)
{
    int ret = 0; // 21
    while (true)
    {
        if (number > 9)
        {
            int val1 = number % 10;
            number /= 10;
            ret += val1 * val1;
        }
        if (number <= 9)
        {
            ret += number * number;
            return ret;
        }
    }
}

int main()
{
    int number;
    std::cin >> number;
    int slow = number, fast = number;
    while(true)
    {
        slow = happylize(slow);
        fast = happylize(fast);
        fast = happylize(fast);
        if(fast == slow)
        {
            if(fast == 1)
            {
                std::cout << "yes";
                break;
            }
            else 
            {
                std::cout << "no";
                break;
            }
        }
    }
    return 0;
}
    */

int happilize(int number)
{
    if(number <= 9)
    {
        return number * number;
    }
    int ret = 0;
    int val1 = 0;
    while(number > 9)
    {
        val1 = number % 10;
        number /= 10;
        ret += val1 * val1;
    }
    return ret;
}

int main()
{
    int number = 2;
    int fast = 2, slow = 2;
    fast = happilize(happilize(fast));
    slow = happilize(slow);
    while(1)
    {
        if(fast == slow)
        {
            break;
        }
        else
        {
            fast = happilize(happilize(fast));
            slow = happilize(slow);
        }
    }
    if(fast == 1)
    {
        std::cout << "true" << std::endl;
    }
    else{
        std::cout << "false" << std::endl;
    }
    return 0;
}
